<template>
  <div>
    <el-form
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item class="mail" label="手机号码/邮箱" prop="userName">
        <el-input
          v-model="userName"
          class="input"
          placeholder="请输入手机号码/邮箱"
        />
        <i class="iconfont icon-personal user" />
        <div class="box">
          <div v-show="state" class="error-msg">{{ hintUser }}</div>
        </div>
      </el-form-item>
    </el-form>
    <button class="btn" @click="next">下一步</button>
  </div>
</template>
<script>
import { REGEX_MOBILE_EMAIL } from '@/js/regex'
import { forgetPassword } from '@/api/reset-password'
export default {
  name: 'FirstRestPWD',
  data() {
    return {
      userName: undefined,
      disable: false,
      hintUser: '',
      state: false
    }
  },
  methods: {
    next() {
      if (!this.userName) {
        this.hintUser = '请先填写账号'
        this.state = true
        return
      }
      if (!REGEX_MOBILE_EMAIL.test(this.userName)) {
        // this.$message('账号只能是手机号或邮箱地址')
        this.hintUser = '账号只能是手机号或邮箱地址'
        this.state = true
        return
      }
      this.disable = true
      forgetPassword(this.userName).then(res => {
        if (res.data) {
          this.$emit('setCodeForm', {
            uuid: res.data,
            userName: this.userName
          })
          this.$emit('next')
          this.state = false
        } else {
          this.disable = false
          this.hintUser = '账号不存在'
          this.state = true
        }
      }).catch(() => {
        this.disable = false
      })
    }
  }
}
</script>
<style scoped lang="scss">
.password {
  padding-top: 127px;
  padding-bottom: 87px;
  background: #f5f5f5;
  .password-content {
    background: #ffffff;
    .contents {
      height: 600px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .box{
        height: 20px;
        line-height: 20px;
        .error-msg{
          text-align: left;
          padding-left: 30px;
          color: #f56c6c;
        }
      }
      .one {
        margin: 48px 0 30px 339px;
        .input {
          position: relative;
        }
        .user {
          position: absolute;
          left: 50px;
          font-size: 24px;
          top: -1px;
        }
      }
      .btn {
        background: #ff3b30;
        width: 400px;
        height: 42px;
        line-height: 42px;
        text-align: center;
        color: #ffffff;
        cursor: pointer;
        border-radius: 3px;
        margin-left: 130px;
        font-size: 18px;
      }
    }
  }
  /deep/.contents {
    .el-form-item__error {
      margin-left: 30px;
    }
  }
  /deep/ .contents {
    .el-input {
      width: 400px;
      height: 42px;
    }
    .el-form-item__label {
      width: 130px !important;
    }
  }
  /deep/ .steps {
    .el-steps {
      position: absolute;
      width: 1000px;
      top: 40px;
      right: -340px;
    }
  }
  /deep/ .one {
    .el-input__inner {
      text-indent: 40px;
    }
  }
  /deep/ .three-from {
    .el-input__inner {
      text-indent: 40px;
    }
  }
  /deep/ .from {
    .el-input__inner {
      text-indent: 40px;
    }
  }
}
</style>
